<?php  
 // session_start();
include_once('init.php');
          if(!empty($_POST)){
            //开启session
          
  //链接到数据库对应的数据
          

                //$_POST的所有数据存储在临时变量中
                  $title=$_POST['title'];
                  $type=$_POST['type'];
                  $content=$_POST['content'];
                  $auther=$_POST['auther'];
                  $send_user=$_SESSION['admin']['username'];
 
//编写插入语句 
$sql = "insert into `news`(`title`,`type`,`content`,`auther`,`send_user`)values('$title','$type','$content','$auther','$send_user')";
//编写执行语句
mysqli_query($link,$sql);
//mysqli_affected_rows($link)语句可以检测语句是否执行成功
  $_rows=mysqli_affected_rows($link);

//如果$_rows>0说明成功
if ($_rows>0) {
    echo '<script> alert ("新闻数据添加成功");location.href="news-list.php";</script>';die;
       
}else{

    echo '<script> alert ("新闻数据添加失败");history.go(-1);</script>';
        die;
}


}
//链接news.html的语句
include (VIEW_PATH.$admin.'layout.html');

?>

